/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 */

package com.huawei.rpc.server.register;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Lijl
 * @ClassName DefaultServiceRegister
 * @Description 默认服务注册
 * @Date 2022/2/15 15:19
 * @Version 1.0
 */
public abstract class DefaultServiceRegister implements ServiceRegister{

    private Map<String, ServiceObject> serviceMap = new HashMap<>();
    protected String protocol;
    protected int port;

    /**
     * @Author lijl
     * @MethodName register
     * @Description 缓存服务持有对象
     * @Date 16:10 2022/3/11
     * @Version 1.0
     * @param soList
     * @return: void
    **/
    @Override
    public void register(List<ServiceObject> soList) throws Exception {
        if (soList==null&&soList.size()>0){
            throw new IllegalAccessException("Service object information cannot be empty");
        }
        soList.forEach(so -> this.serviceMap.put(so.getName(), so));
    }

    /**
     * @Author lijl
     * @MethodName getServiceObject
     * @Description 获取服务持有对象
     * @Date 16:11 2022/3/11
     * @Version 1.0
     * @param name
     * @return: com.huawei.rpc.server.register.ServiceObject
    **/
    @Override
    public ServiceObject getServiceObject(String name) {
        return this.serviceMap.get(name);
    }
}
